<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TMDT Project Admin</title>
<link rel="stylesheet" href="/admin/resources/css/reset.css"
	type="text/css" media="screen" />
<link rel="stylesheet" href="/admin/resources/css/style.css"
	type="text/css" media="screen" />
<link rel="stylesheet" href="/admin/resources/css/invalid.css"
	type="text/css" media="screen" />
<script type="text/javascript"
	src="/admin/resources/scripts/jquery-1.3.2.min.js"></script>

<script type="text/javascript"
	src="/admin/resources/scripts/simpla.jquery.configuration.js"></script>
<script type="text/javascript" src="/admin/resources/scripts/facebox.js"></script>
<script type="text/javascript"
	src="/admin/resources/scripts/jquery.wysiwyg.js"></script>
<script type="text/javascript"
	src="/admin/resources/scripts/jquery.datePicker.js"></script>
<script type="text/javascript"
	src="/admin/resources/scripts/jquery.date.js"></script>
	
<script type="text/javascript"
	src="/admin/scripts/jquery-1.8.3.min.js"></script>	
<script type="text/javascript"
	src="/admin/scripts/auction.js"></script>
<script type="text/javascript"> 
	var auctionList = new Array();
	var deleteAuctionList = new Array();
	function deleteOneAuction(auctionID){
		deleteAuctionList = new Array();
		var answer = confirm("Are you sure to delete row with auctionID = "+auctionID+"?" );
		if (answer){
			deleteAuctionList.push(auctionID);
			deleteAuctions(deleteAuctionList);
		};
	}

	function deleteSelectedAuctions(){
		deleteAuctionList = new Array();
		$('table tbody tr input:checkbox[class="auction_check"]:checked').each(function (){
				deleteAuctionList.push($(this).attr('refid'));
			} 
		);
		var answer = confirm("Are you sure to delete these rows ?" );
		if (answer){
			deleteAuctions(deleteAuctionList);
		};
	}
</script>
</head>
<body>
<div id="body-wrapper"><!-- Wrapper for the radial gradient background -->

<div id="sidebar">
<div id="sidebar-wrapper"><!-- Sidebar with logo and menu -->

<h1 id="sidebar-title"><a href="#">TMDT Project Admin</a></h1>

<!--  Logo (221px wide) --> 
	<a href="#"><img id="logo"
	src="/admin/resources/images/logo.png" alt="Simpla Admin logo" /></a>

			
			<?php include_once 'all_auctions_main_nav.php'?>
			

			
		</div>
</div>
<!-- End #sidebar -->
<div id="clear"></div>
<div id="main-content"><!-- Main Content Section with everything -->
	<?php include_once '../shortcut_buttons.php' ?>
		
<noscript>
<!-- Show a notification if the user has disabled javascript -->
<div class="notification error png_bg">
<div>Javascript is disabled or is not supported by your browser. Please
<a href="http://browsehappy.com/" title="Upgrade to a better browser">upgrade</a>
your browser or <a
	href="http://www.google.com/support/bin/answer.py?answer=23852"
	title="Enable Javascript in your browser">enable</a> Javascript to
navigate the interface properly.</div>
</div>
</noscript>


	<?php include_once '../config.php' ?>

			

			

			<div class="clear"></div>
			<!-- End .clear -->
<div class = "message">			

</div>
<div class="content-box"><!-- Start Content Box -->

<div class="content-box-header">

<h3>Auctions</h3>

<ul class="content-box-tabs">

	<li><a href="#all_auctions_tab">All Auctions</a></li>

</ul>

<div class="clear">
</div> <!-- End .clear -->
</div><!-- End .content-box-header -->
			<?php 						
				$connection = mysql_connect ( $host, $username, $password ) or die ( "Could not connect to MySql" . mysql_error () );
				mysql_select_db ( $db, $connection ) or die ( "Could not connect to MySql" . mysql_error () );
				$statement = "select count(auctionID) from auction_view";
				$result = mysql_query($statement);
				if (! $result) {
					$message = "MySQL: Error " . mysql_errno () . " : " . mysql_error ();
		    ?>
				
				<div class="notification error png_bg">
					<a href="#" class="close"><img src="/admin/resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close"/></a>
					<div>
						<?php echo $statement."  ".$message; ?>	
					</div>
				</div>	
				<div class="clear"></div>
			<?php 
				}
				$row = mysql_fetch_array($result,MYSQL_NUM);
				$num_auctions= $row[0];
				$num_pages = ceil($row[0]/10);
				
			?>	
				<div class="content-box-content">
					
					<div class="tab-content default-tab" id="all_auctions_tab"> <!-- This is the target div. id must match the href of this div's tab -->
				
						<table>
							
							<thead>
								<tr>
								   <th><input class="check-all" type="checkbox" /></th>
								 	<th>Auction ID </th>
								   <th>Auction Name</th>
								   <th>Product Name </th>
								   <th>Status</th>
								   <th>Start Time</th>
								   <th>End Time</th>
								   <th>Product Origion Price </th>
								   <th>Auction Price</th>
								   <th>Quantity</th>
								   <th>Last Bid User</th>
								   <th>Price per Bid</th>
								   <th>Action</th>
								</tr>
								
							</thead>
						 
							<tfoot>
								<tr>
									<td colspan="6">
										<div class="bulk-actions align-left">
											<a class="button" href="#" onclick = "getAllAuctionDetail()">Refresh</a>
											<a class="button" href="#" onclick = "deleteSelectedAuctions()">Delete Selected Auctions</a>
										</div>
										

										<div class="clear"></div>
									</td>
								</tr>
							</tfoot>

							<tbody class="auction_row">
							<?php
								$load_auctions_error= false; 
								$statement = "select * from auction_view";
								$result = mysql_query($statement);
								if (! $result) {
									$message = "MySQL: Error " . mysql_errno () . " : " . mysql_error ();
									$load_auctions_error = true;
									die($message);
								}

								while ($row = mysql_fetch_assoc($result)){
									$str = "updateauction.php" . "?id=" . $row['auctionID'];
							?>
								
									 <script type="text/javascript">
 										auctionList.push(<?php echo $row["auctionID"]?>);
 									 </script>
							
								
									<tr ref='row-<?php echo $row["auctionID"]?>' >
									
									<td><input class="auction_check" type="checkbox" refid='<?php echo $row["auctionID"]?>' /></td>
									<td><span class="auctionID"><?php echo $row["auctionID"]?> </span></td>
									<td><span class="name"><?php echo $row["name"]?> </span></td>
									<td><span class="pro_name"><?php echo $row["pro_name"]?> </span></td>
									<td><span class="status"><?php 
									$status = "open";
									if ( strtotime($row ['end_time'])< strtotime('now') )
										 $status = "closed";
									if (strtotime($row ['start_time'])> strtotime('now'))
										$status = "Not started";
									 echo $status;
									 ?>
									 </span>
									 </td>
									<td><span class="start_time"> <?php echo $row["start_time"]?> </span> </td>
									<td ><span class="end_time"><?php echo $row["end_time"]?></span></td>
									<td><span class="price"><?php echo ltrim($row["price"],'0')?> </span></td>
									<td> <span class="auction_price"><?php echo$row["auction_price"]?></span> </td>
									<td> <span class="quantity"><?php echo $row["quantity"]?> </span> </td>
									<td ><span class = "current_user_bid"><?php echo$row["current_user_bid"]?></span> </td>
									<td> <span class="price_per_bid"><?php echo$row["price_per_bid"]?></span> </td>
									
									<td>
										<!-- Icons -->

										 <a title="Edit" href = '<?php echo $str ?>' ><img src="/admin/resources/images/icons/pencil.png" alt="Edit" /></a>
										 <a href="#" title="Delete" onclick = "deleteOneAuction(<?php echo $row['auctionID'] ?>)"><img src="/admin/resources/images/icons/cross.png" alt="Delete" /></a> 
									
									</td>
									
								 </tr>
								
								<?php 
								}
								mysql_close($connection);
								?>
									</tbody>
							
						</table>
						
					</div> <!-- End #tab1 -->
					

<!-- End .content-box-content --></div>
<!-- End .content-box --></div>

			

<div class="clear"></div>

			<?php /*include_once 'notifications.php'*/?>
			<?php /*include_once 'footer.php'*/?>
			

			
			

			
		</div>
<!-- End #main-content --></div>
</body>
</html>


